#include <stdio.h>

// 起泡法排序
void bubbleSort(int arr[], int n) {
    int i, j, temp;
    for(i = 0; i < n-1; i++) {
        for(j = 0; j < n-1-i; j++) {
            if(arr[j] < arr[j+1]) {
                temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
    }
}

// 选择法排序
void selectionSort(int arr[], int n) {
    int i, j, max_idx, temp;
    for(i = 0; i < n-1; i++) {
        max_idx = i;
        for(j = i+1; j < n; j++) {
            if(arr[j] > arr[max_idx]) {
                max_idx = j;
            }
        }
        temp = arr[i];
        arr[i] = arr[max_idx];
        arr[max_idx] = temp;
    }
}

int main() {
    int arr1[] = {5, 2, 8, 1, 9, 3};
    int arr2[] = {5, 2, 8, 1, 9, 3};
    int n = 6, i;
    
    printf("原数组: ");
    for(i = 0; i < n; i++) printf("%d ", arr1[i]);
    
    bubbleSort(arr1, n);
    printf("\n起泡法排序后: ");
    for(i = 0; i < n; i++) printf("%d ", arr1[i]);
    
    selectionSort(arr2, n);
    printf("\n选择法排序后: ");
    for(i = 0; i < n; i++) printf("%d ", arr2[i]);
    
    return 0;
}